'''
Author: Diana Tang
Date: 2025-04-05 00:23:12
LastEditors: Diana Tang
Description: some description
FilePath: /pub-scholar-assist/compress_mp4.py
'''
import subprocess

def compress_mp4(input_path, output_path):
    # 使用libx264重新编码，crf=23 保持高画质，preset设置为slow优化压缩率
    command = [
        'ffmpeg',
        '-i', input_path,
        '-vcodec', 'libx264',
        '-crf', '23',  # 可调范围：18~28，数值越低，画质越好，文件越大
        '-preset', 'slow',  # 可选值：ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow
        '-acodec', 'aac',
        '-b:a', '128k',  # 音频比特率
        '-movflags', '+faststart',  # 优化网页播放性能
        output_path
    ]
    subprocess.run(command)

# 使用示例
compress_mp4("世界健康论坛20241103-庄宁.mp4", "output_世界健康论坛20241103-庄宁.mp4")
